package bb.lanxing.adapter.mine;

import android.util.TypedValue;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import bb.lanxing.R;
import java.util.List;
import android.graphics.Typeface;

public class HistoryYearAdapter extends ArrayAdapter<Integer> {
    private int selected;

    public HistoryYearAdapter(Context context, int i, List<Integer> list) {
        super(context, i, list);
    }

    @Override
    public View getDropDownView(int i, View view, ViewGroup viewGroup) {
        View dropDownView = super.getDropDownView(i, view, viewGroup);
        makeStyleTextItem((TextView) dropDownView, String.valueOf(getItem(i)), this.selected == i);
        return dropDownView;
    }

    @NonNull
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View view2 = super.getView(i, view, viewGroup);
        makeStyleTextItem((TextView) view2, String.valueOf(getItem(i)), true);
        return view2;
    }

    private static void makeStyleTextItem(TextView textView, String str, boolean iSelected) {
        textView.setTextColor(ContextCompat.getColor(textView.getContext(), iSelected ? R.color.grey_666666 : R.color.grey_B2666666));
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(str);
        spannableStringBuilder.setSpan(new StyleSpan(Typeface.BOLD), 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannableStringBuilder);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, iSelected ? 18.0f : 16.0f);//2
    }

    public void setSelected(int i) {
        this.selected = i;
    }
}